﻿namespace Contoso.ActiveDirectory {

    #region Usings
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks; 
    #endregion

    [Serializable]
    public class OrganizationAttributes : IOrganizationAttributes {

        #region Members

        public static readonly string[] AttributesToGet;

        #region Organization properties
        public string Company { get; private set; }
        public string Department { get; private set; }

        /// <summary>
        /// The distinguished names of the objects that have their Manager attribute set to this object
        /// </summary>
        /// <remarks>Backlink attribute</remarks>
        public IReadOnlyList<string> DirectReports { get; private set; }
        public string Manager { get; private set; }
        public string Title { get; private set; }
        #endregion

        #endregion

        #region Constructors
        static OrganizationAttributes() {

            AttributesToGet = new string[]
            {
                "company",
                "department",
                "directReports",
                "manager",
                "title",
            };

        }

        public OrganizationAttributes() {
            this.Company = string.Empty;
            this.Department = string.Empty;
            this.DirectReports = new List<string>();
            this.Manager = string.Empty;
            this.Title = string.Empty;
        }
        #endregion

        #region Methods
        public void ProcessResults(Dictionary<string, object[]> attributes) {

            if (attributes.ContainsKey("company")) this.Company = attributes["company"][0].ToString();
            if (attributes.ContainsKey("department")) this.Department = attributes["department"][0].ToString();
            this.DirectReports = ADDataAccess.GetMultiValuedAttribute<string>("directReports", attributes);
            if (attributes.ContainsKey("manager")) this.Manager = attributes["manager"][0].ToString();
            if (attributes.ContainsKey("title")) this.Title = attributes["title"][0].ToString();

        }
        #endregion
    }
}
